#include <iostream>
#include <vector>
using namespace std;
//98.10 %
class Solution
{
  public:
	int maxArea(vector<int> &height)
	{
		int l = 0, r = height.size() - 1, area;
		int max = (r - l) * (height[l] < height[r] ? height[l] : height[r]);
		while (l < r)
		{
			if (height[l] < height[r])
				l++;
			else
				r--;
			area = (r - l) * (height[l] < height[r] ? height[l] : height[r]);
			max = max > area ? max : area;
		}
		return max;
	}
};

int main()
{
	int arr[9] = {1, 8, 6, 2, 5, 4, 8, 3, 7};
	vector<int> myVector(arr, arr + 9);
	cout << Solution().maxArea(myVector) << endl;
	return 0;
}
